﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ASApplication;

namespace ASPresentation
{
    /// <summary>
    /// 这里并没有应用mvvm，只是根据自己的理解做了一些工作
    /// </summary>
    public class AppViewModel
    {


        protected AppViewModel()
        {

            _tvProject = new ProjectViewModel();

            this._toolBarVM = new ToolBarViewModel();

        }



        static AppViewModel current;

        public static AppViewModel Current
        {
            get
            {

                if (current == null)
                {
                    current = new AppViewModel();

                }

                return AppViewModel.current;

            }

        }



        ProjectViewModel _tvProject;

        public ProjectViewModel TvProject
        {
            get { return _tvProject; }
            set { _tvProject = value; }
        }


        ToolBarViewModel _toolBarVM;

        public ToolBarViewModel ToolBarVM
        {
            get { return _toolBarVM; }
            set { _toolBarVM = value; }
        }







        public void Init()
        {
            ProjectService.CurrentService.ProjChanged += new FXnaInfrastructure.ProjHandler(CurrentService_ProjChanged);

            //初始化,子项目信息

            this._toolBarVM.Init();



        }



        protected void ResetViewModel()
        {


            this._tvProject.Refresh();



        }



        void CurrentService_ProjChanged(FXnaInfrastructure.ProjChangedType chType)
        {

            switch (chType)
            {
                case FXnaInfrastructure.ProjChangedType.NEW:
                    this.ResetViewModel();
                    break;
                case FXnaInfrastructure.ProjChangedType.SAVE:
                    break;
                case FXnaInfrastructure.ProjChangedType.CLOSE:
                    this.ResetViewModel();
                    break;
                case FXnaInfrastructure.ProjChangedType.OPEN:

                    this.ResetViewModel();
                    break;
                default:
                    break;
            }

        }



     










    }
}
